---
title: About two-factor authentication
redirect_from:
  - /getting-started/using-two-factor-authentication
---

[Two-factor authentication (2FA)][2fa] protects against unauthorized access to your account by confirming your identity using:

- Something you know (e.g., a password).
- Something you have (e.g., an ID badge or a cryptographic key).
- Something you are (e.g., a fingerprint or other biometric data).

When you enable 2FA, you will be prompted for a second form of authentication before performing certain actions on your account or packages to which you have write access. Depending on your 2FA configuration you will be either prompted to authenticate with a [security-key][webauthn] or a [time-based one-time password (TOTP)][totp].

- The security-key flow allows you to use biometric devices such as Apple [Touch ID][touch-id], [Face ID][face-id] or [Windows Hello][windows-hello] as well as physical keys such as [Yubikey][yubikey], [Thetis][thetis] or [Feitian][feitian] as your 2FA.
- To configure TOTP you will need to install an authenticator application that can generate OTPs such as [Authy][authy], [Google Authenticator][google-authenticator], or [Microsoft Authenticator][microsoft-authenticator] on your mobile device.

<Note>

**Note:** Two-factor authentication provides the best possible security for your account against attackers. We strongly recommend enabling 2FA on your account as soon as possible after you sign up.

</Note>

## Two-factor authentication on npm

Two-factor authentication on npm can be enabled for authorization and writes, or authorization only.

### Authorization and writes

By default, 2FA is enabled for authorization and writes. We will request a second form of authentication for certain authorized actions, as well as write actions.

| Action                                            | CLI command                                            |
| :------------------------------------------------ | :----------------------------------------------------- |
| Log in to npm                                     | [`npm login`][login]                                   |
| Change profile settings (including your password) | [`npm profile set`][profile-set]                       |
| Change 2FA modes for your user account            | [`npm profile enable-2fa auth-and-writes`][2fa-enable] |
| Disable 2FA for your user account                 | [`npm profile disable-2fa`][2fa-disable]               |
| Create tokens                                     | [`npm token create`][token-create]                     |
| Revoke tokens                                     | [`npm token revoke`][token-revoke]                     |
| Publish packages                                  | [`npm publish`][publish]                               |
| Unpublish packages                                | [`npm unpublish`][unpublish]                           |
| Deprecate packages                                | [`npm deprecate`][deprecate]                           |
| Change package visibility                         | [`npm access public/restricted`][access]               |
| Change user and team package access               | [`npm access grant/revoke`][access]                    |
| [Change package 2FA requirements][pkg-2fa]        | [`npm access 2fa-required/2fa-not-required`][access]   |

### Authorization only

If you enable 2FA for authorization only. We will request a second form of authentication only for certain authorized actions.

| Action                                            | CLI command                                      |
| :------------------------------------------------ | :----------------------------------------------- |
| Log in to npm                                     | [`npm login`][login]                             |
| Change profile settings (including your password) | [`npm profile set`][profile-set]                 |
| Change 2FA modes for your user account            | [`npm profile enable-2fa auth-only`][2fa-enable] |
| Disable 2FA for your user account                 | [`npm profile disable-2fa`][2fa-disable]         |
| Create tokens                                     | [`npm token create`][token-create]               |
| Revoke tokens                                     | [`npm token revoke`][token-revoke]               |

[login]: https://docs.npmjs.com/cli/adduser
[profile-set]: https://docs.npmjs.com/cli/profile
[2fa-enable]: https://docs.npmjs.com/cli/profile
[2fa-disable]: https://docs.npmjs.com/cli/profile
[token-create]: https://docs.npmjs.com/cli/token
[token-revoke]: https://docs.npmjs.com/cli/token
[publish]: https://docs.npmjs.com/cli/publish
[unpublish]: https://docs.npmjs.com/cli/unpublish
[deprecate]: https://docs.npmjs.com/cli/deprecate
[access]: https://docs.npmjs.com/cli/access
[pkg-2fa]: /requiring-2fa-for-package-publishing-and-settings-modification
[authy]: https://authy.com/download/
[google-authenticator]: https://support.google.com/accounts/answer/1066447
[microsoft-authenticator]: https://www.microsoft.com/security/mobile-authenticator-app
[webauthn]: https://webauthn.guide/
[can-i-use]: https://caniuse.com/#search=webauthn
[u2f]: https://en.wikipedia.org/wiki/Universal_2nd_Factor
[windows-hello]: https://support.microsoft.com/en-us/windows/learn-about-windows-hello-and-set-it-up-dae28983-8242-bb2a-d3d1-87c9d265a5f0
[touch-id]: https://support.apple.com/en-gb/HT204587
[face-id]: https://support.apple.com/en-us/HT208108
[yubikey]: https://www.yubico.com/
[thetis]: https://thetis.io/
[feitian]: https://www.ftsafe.com/
[totp]: https://en.wikipedia.org/wiki/Time-based_one-time_password
[2fa]: https://en.wikipedia.org/wiki/Multi-factor_authentication
